package com.kai;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

@RestController
@Slf4j
public class MailController {

    @Resource
    private MailUtils mailUtils;


    @PostMapping("/mail")
    public String sendMain(MultipartFile mpFile) throws IOException, MessagingException {
        String filename = mpFile.getOriginalFilename();
        log.info("文件名：{}",filename);

        //InputStream inputStream = file.getInputStream();
        //mailUtils.sendMail("测试","3427173515@qq.com","内容测试",filename,inputStream);


        //InputStream stream = HttpUtils.returnBitMap("https://2bda6q3rxsaj.guyubao.com/test/sss.pdf");

        //InputStream inputStream = new URL("https://2bda6q3rxsaj.guyubao.com/test/sss.pdf").openStream();
        //mailUtils.sendMail("测试","3427173515@qq.com","内容测试","sss.pdf",stream);

        File file = new File("C:\\Users\\66245\\Downloads\\sss.pdf");
        mailUtils.sendMail("测试","3427173515@qq.com","内容测试","sss.pdf",file);
        return "ok";
    }
}
